<script>
export default {
	onLaunch: function(option) {
		this.globalData.readingCount=0
		uni.getSystemInfo({
		    success: ({ model, screenHeight }) => {
		        const iphoneX = /iphone x/i.test(model);
		        const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
		        this.globalData.iphoneX = iphoneX || iphoneNew;
		    }
		});
		this._log('App Launch');
	},
	methods: {
		previewImg(arr,index=0) {
		    uni.previewImage({
		      current: arr[index], // 当前显示图片的http链接  
		      urls: arr // 需要预览的图片http链接列表  
		    })
		},
		  
		/**
		 * 过滤掉空数组
		 * @param arr
		 * @returns {*}
		 */
		// arr=[0,1,,,2];
		// console.log(removeEmptyArray(arr))//[0,1,2]   这个返回0，1，2
		removeEmptyArray(arr) {
			for (var i = 0; i < arr.length; i++) {
				if (arr[i] == undefined) {
					arr.splice(i, 1);
					i = i - 1; // i - 1 ,因为空元素在数组下标 2 位置，删除空之后，后面的元素要向前补位，
					// 这样才能真正去掉空元素,觉得这句可以删掉的连续为空试试，然后思考其中逻辑
				}
			}
			return arr;
		},
		_log(...consoleStr) {
			let _console;
			if (!this.globalData.DEBUG) return;
			let h = new Date();
			let str = h.getHours() + ':' + h.getMinutes() + ':' + h.getSeconds() + '.' + h.getMilliseconds();
			let pageList = getCurrentPages();
			const args = ['【', ...consoleStr, '】', pageList.length >= 1 ? pageList[pageList.length - 1].route : ''];
			Array.prototype.splice.call(args, 0, 0, str);
			// eslint-disable-next-line no-console
			if (this.removeEmptyArray([...consoleStr]).length) {
				(_console = console).log.apply(_console, args);
			} else {
				// console.trace();
				args.unshift('【输出有空值】');
				(_console = console).warn.apply(_console, args);
			}
		},
		// 关键字高亮
		searchHighlight(value,keyword,color='#7F4AFF') {
			if (value=='') return keyword; // 搜索关键词为空
			let htmlReg = new RegExp('\<.*?\>', 'i');
			let arrA = new Array();
			//替换HTML标签
			for (let i = 0; true; i++) {
				let m = htmlReg.exec(keyword);
				if (m) {
					arrA[i] = m;
				} else {
					break;
				}
				keyword = keyword.replace(m, '{[(' + i + ')]}');
			}
			let words = unescape(value.replace(/\+/g, ' ')).split(/\s+/);
			//替换关键字
			for (let w = 0; w < words.length; w++) {
				let r = new RegExp('(' + words[w].replace(/[(){}.+*?^$|\\\[\]]/g, '\\$&') + ')', 'ig');
				keyword = keyword.replace(r, "<b style='color:"+color+";'>$1</b>");
			}
			//恢复HTML标签
			for (let i = 0; i < arrA.length; i++) {
				keyword = keyword.replace('{[(' + i + ')]}', arrA[i]);
			}
			return keyword;
		},
		// 发送订阅消息
		requestSubscribeMessage(type,callback){  //type合法值   payOrder ==>下单成功通知   appointment ==>预约成功通知   refund ==>退款状态通知
			uni.requestSubscribeMessage({
			  tmplIds: [this.globalData.subscribeMessage[type]],
			  complete:res=>{
				callback&&callback()
			  }
			})
		}
	},
	onShow: function() {
		this._log('App Show');
	},
	onHide: function() {
		this._log('App Hide');
	},
	globalData: {
		// 公用参数
		iphoneX:false,//机型判断
		readingCount:0,//消息待读数量
		LOGION:false,//判断当前是否登录
		subscribeMessage:{
			"order_success": "kK2ai9RrT1cwgyGlYa_MTtFC53IyQlfNo--OkDiVMsU",//下单成功通知
	        "course_success": "4eYjHG7fupViJntHUE93MdX0116QlqwHI3JT5K3jATs",//授课预约成功通知
	        "refund_result": "5sDSUPmPPl5hdZbaHfzVhtFlnd9e9557RByPn5BWGKk"//退款状态通知
		},//订阅消息数据
		userIdentity:0,//判断当前用户身份， 0 学生  1 老师
		// appToken:'',//token
		BASE_URL:'https://wxapp.well-talk.com', // 一些需要域名拼接的地方在此取值，通用请求文件除外
		DEBUG: false,  //测试时将页面上的app._log更改为console.log  上线相反
		currentTab:0, // tabBar选中项
		addressKey: 'KZTBZ-3YQC3-HEX3E-YAWGI-2L2G3-JLBE3', // 腾讯地址key  https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
		location:{//首页等地址展示的经纬度等信息
			lat:'',
			lng:'',
			city:'',
			address:''
		},
		// 局部公用参数
		searchHistory: [],//搜索记录
		phone:'15036338427' // 电话号码
	}
};
</script>

<style lang="scss">
.look_num{
	font-size: 24rpx;
}
//红点 底部栏，消息页面用到
.red_dot{
	width: 30rpx;
	text-align: center;
	line-height: 30rpx;
	color: #fff;
	background-color: red;
	border-radius: 15rpx;
	top: 0;
	right: 10rpx;
	font-size: 16rpx;
	&.w_35{
		width: 35rpx;
		right: 5rpx;
	}
}
// 消息未读红点
.reading{
	display: block;
	position: absolute;
	width: 20rpx;
	height: 20rpx;
	border-radius: 50%;
	right: 20rpx;
	top: -1rpx;
	background-color: red;
}
view,
text,
image,
input,
textarea {
	box-sizing: border-box;
}
.b-f{
	background-color: #fff!important;
}
.share-btn {
	width: 100%;
	height: 100%;
	position: absolute;
	opacity: 0;
	top: 0;
	left: 0;
}
@font-face {
	font-family: 'BEBAS';
	src: url('~@/static/font/BEBAS___.ttf');
}
$orange: #ffa63e; // 橙色
$green: #1fc181; // 绿色
$violet: #a865ff; // 紫色
$violet1:#7f4aff; // 紫色1
$gery: rgba(37, 39, 72, 0.4); // 灰色
$gery1: #8f8f9a; // 灰色1
$red: #f84136; //红色

$navy_blue: #252748; // 深蓝色
.navy_blue {
	color: $navy_blue;
}
.orange {
	color: $orange;
}
.green {
	color: $green;
}
.violet {
	color: $violet;
}
.violet1 {
	color: $violet1;
}
.gery {
	color: $gery;
}
.gery1 {
	color: $gery1;
}
.red {
	color: $red;
}
.c-f{
	color: #fff;
}
.b_ {
	&orange {
		border-color: $orange !important;
	}
	&green {
		border-color: $green !important;
	}
	&violet {
		border-color: $violet !important;
	}
	&gery {
		border-color: $gery !important;
	}
	&g_{ // 背景色
		&navy_blue{
			background-color: $navy_blue !important;
		}
		&violet1{
			background-color: $violet1 !important;
		}
		&gery1{
			background-color: $gery1 !important;
		}
	}
}
.dis_ {
	&none{
		display: none;
	}
	&b {
		display: block;
	}
	&ib {
		display: inline-block;
	}
	&f {
		display: flex;
	}
	&if {
		display: inline-flex;
	}
}
@for $i from 1 through 9 {
	.f-c-#{$i} {
		color: #111 * $i;
	}
	.f_#{$i} {
		font-weight: 100 * $i;
	}
}
.f_ {
	&f{
		color: #fff;
	}
	&regular,
	&normal {
		font-weight: 400;
	}
	&medium {
		font-weight: 500;
	}
	&semibold {
		font-weight: 600;
	}
	&bold {
		font-weight: 700;
	}
}

// 通用end
.font_bebas {
	font-family: 'BEBAS';
}

.language_type_text {
	font-size: 24rpx;
	line-height: 40rpx;
	padding:0rpx 8rpx;
	border-radius: 2rpx 8rpx 2rpx 8rpx;
	&[class*='lan_'] {
		color: #fff;
	}
	&.lan_ {
		&text_default {
			background-color: #f6f6f8;
		}
		&default {
			background-color: #e1e2ea;
			border-radius: 24rpx 24rpx 0rpx 24rpx;
		}
		&korean {
			//韩语
			background-color: #797feb;
		}
		&japanese {
			// 日语
			background-color: #db6eac;
		}
		&english {
			// 英语
			background-color: #ffa748;
		}
		&vietnamese {
			// 越南语
			background-color: #46aa5d;
		}
		&arabic {
			// 阿拉伯语
			background-color: #001d59;
		}
		&german {
			// 德语
			background-color: #5ab39a;
		}
		&italian {
			// 意大利语
			background-color: #1f8fa6;
		}
	}
}

/*每个页面公共css */
.page,
.switch_tab_page {
	background-color: #f8f8f8;
}
.page { // 组件内谨慎用该类名
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	&:not(.max){
		min-height: calc(100vh - constant(safe-area-inset-bottom));
		min-height: calc(100vh - env(safe-area-inset-bottom));
	}
	&.max{
		max-height: calc(100vh - constant(safe-area-inset-bottom));
		max-height: calc(100vh - env(safe-area-inset-bottom));
	}
}
.switch_tab_page {
	min-height: calc(100vh - constant(safe-area-inset-bottom) - 98rpx);
	min-height: calc(100vh - env(safe-area-inset-bottom) - 98rpx);
	padding-bottom: calc(constant(safe-area-inset-bottom) + 98rpx);
	padding-bottom: calc(env(safe-area-inset-bottom) + 98rpx);
}

.onelist-hidden {
	display: block; //行内元素处理
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.twolist-hidden {
	display: block;
	display: -webkit-box;
	word-break: break-all;
	text-overflow: ellipsis;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

@for $i from 1 through 5 {
	.ts-#{$i} {
		transition: all 0.1s * $i;
	}
}
$starNum: 16;
@while $starNum<=48 {
	.f_#{$starNum} {
		font-size: $starNum + 0rpx;
	}
	.m_l_#{$starNum} {
		margin-left: $starNum + 0rpx;
	}
	.m_r_#{$starNum} {
		margin-right: $starNum + 0rpx;
	}
	$starNum: $starNum + 2;
}
.f_56 {
	font-size: 56rpx;
}
.m_l_70 {
	margin-left: 70rpx;
}
.m_b_0{
	margin-bottom: 0!important;
}
.p_b_0{
	padding-bottom: 0!important;
}

.v-h {
	visibility: hidden;
}
.tf-180 {
	transform: rotate(-180deg);
}

.tf-90 {
	transform: rotate(90deg);
}

.dis-block {
	display: block;
}
.dis-iblock {
	display: inline-block;
}

.dis-flex {
	display: flex !important;
}

.flex-box {
	flex: 1;
}

.flex-box .num {
	margin-left: 16rpx;
}
.flex-dir-row {
	flex-direction: row;
}

.flex-dir-column {
	flex-direction: column;
}

.flex-x-center {
	justify-content: center;
}

.flex-x-between {
	justify-content: space-between;
}

.flex-x-around {
	justify-content: space-around;
}

.flex-x-end {
	justify-content: flex-end;
}

.flex-y-center {
	align-items: center;
}

.flex-y-end {
	align-items: flex-end;
}

.flex-five {
	box-sizing: border-box;
	flex: 0 0 50%;
}

.flex-three {
	float: left;
	width: 33.3%;
}

.flex-four {
	box-sizing: border-box;
	flex: 0 0 25%;
}

.t-l {
	text-align: left;
}

.t-c {
	text-align: center;
}

.t-r {
	text-align: right;
}

.p-a {
	position: absolute;
}

.p-r {
	position: relative;
}

.fl {
	float: left;
}

.fr {
	float: right;
}

.clear::after {
	clear: both;
	content: ' ';
	display: table;
}

.oh {
	overflow: hidden;
}

@keyframes f {
	0% {
		transform: rotate(0deg);
	}
	to {
		transform: rotate(1turn);
	}
}
.weui-loading {
	width: 20px;
	height: 20px;
	display: inline-block;
	vertical-align: middle;
	-webkit-animation: f 1s steps(12) infinite;
	animation: f 1s steps(12) infinite;
	background: transparent
		url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 100 100'%3E%3Cpath fill='none' d='M0 0h100v100H0z'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E9E9E9' rx='5' ry='5' transform='translate(0 -30)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23989697' rx='5' ry='5' transform='rotate(30 105.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%239B999A' rx='5' ry='5' transform='rotate(60 75.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23A3A1A2' rx='5' ry='5' transform='rotate(90 65 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23ABA9AA' rx='5' ry='5' transform='rotate(120 58.66 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23B2B2B2' rx='5' ry='5' transform='rotate(150 54.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23BAB8B9' rx='5' ry='5' transform='rotate(180 50 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23C2C0C1' rx='5' ry='5' transform='rotate(-150 45.98 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23CBCBCB' rx='5' ry='5' transform='rotate(-120 41.34 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23D2D2D2' rx='5' ry='5' transform='rotate(-90 35 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23DADADA' rx='5' ry='5' transform='rotate(-60 24.02 65)'/%3E%3Crect width='7' height='20' x='46.5' y='40' fill='%23E2E2E2' rx='5' ry='5' transform='rotate(-30 -5.98 65)'/%3E%3C/svg%3E")
		no-repeat;
	background-size: 100%;
}
</style>
